﻿using Learun.Util;
using System;
using System.Collections.Generic;
using static Learun.Application.TwoDevelopment.ZZDT_EC.ProjectSugar;
using static Learun.Util.SqlSugar.SqlSugarHelper;

namespace Learun.Application.TwoDevelopment.ZZDT_EC
{
    /// <summary>
    /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
    /// Copyright (c) 2013-2018 Hexagon PPM
    /// 创 建：超级管理员
    /// 日 期：2022-06-21 15:32
    /// 描 述：端子表
    /// </summary>
    public class ec_PanelStripTermBLL : ec_PanelStripTermIBLL
    {
        ec_PanelStripTermService ec_PanelStripTermService; 
        public ec_PanelStripTermBLL()
        {
            ec_PanelStripTermService = new ec_PanelStripTermService();
        }
        #region 获取数据
        /// <summary>
        /// 获取列表 
        /// <param name="ProjId"></param>
        /// <summary>
        /// <returns></returns>
        public IEnumerable<ec_PanelStripTermEntity> GetList(string queryJson, Pagination pagination = null)
        {
            try
            {
                var queryParam = queryJson.ToJObject();
                string ProjectId = queryParam["ProjectId"]?.ToString();
                string StripID = queryParam["StripID"]?.ToString();
                string ChannelID = queryParam["ChannelID"]?.ToString();
                string TermID = queryParam["TermID"]?.ToString();
                string Term_No = queryParam["Term_No"]?.ToString();
                var tableName = TableName<ec_PanelStripTermEntity>(ProjectId);

                var query = Db.Queryable<ec_PanelStripTermEntity>().AS(tableName)
                    .WhereIF(!string.IsNullOrEmpty(StripID), x => x.StripID == StripID)
                    .WhereIF(!string.IsNullOrEmpty(ChannelID), x => x.ChannelID == ChannelID)
                    .WhereIF(!string.IsNullOrEmpty(TermID), x => x.TermID == TermID)
                    .WhereIF(!string.IsNullOrEmpty(Term_No), x => x.Term_No.Contains(Term_No));
                List<ec_PanelStripTermEntity> list;
                if (pagination == null)
                {
                    list = query.ToList();
                }
                else
                {
                    list = query.ToPageList(pagination.page, pagination.rows);
                }
                return list;
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }
        /// <summary>
        /// 获取实体数据
        /// <param name="keyValue">主键</param>
        /// <summary>
        /// <returns></returns>
        public ec_PanelStripTermEntity GetEntity(string keyValue, string ProjectId)
        {
            try
            {
                return ec_PanelStripTermService.GetEntity(keyValue, ProjectId);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }

        #endregion
        #region 提交数据
        /// <summary>
        /// 删除实体数据
        /// <param name="keyValue">主键</param>
        /// <summary>
        /// <returns></returns>
        public void DeleteEntity(string ProjectId, string keyValue)
        {
            try
            {
                ec_PanelStripTermService.DeleteEntity(ProjectId, keyValue);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }
        /// <summary>
        /// 保存实体数据（新增、修改）
        /// <param name="keyValue">主键</param>
        /// <summary>
        /// <returns></returns>
        public void SaveEntity(string ProjectId, string keyValue, ec_PanelStripTermEntity entity)
        {
            try
            {
                ec_PanelStripTermService.SaveEntity(ProjectId, keyValue, entity);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }

        #endregion

    }
}
